function drawQMEANLocal(a,n,p,y,e){var q=["lq-chart"+(n?"-"+n:"")];if((e||!(0<$("#"+q[0]+" svg").length))&&a){if(1<a.length)for(e=0;e<a.length;e++)q.push("lq-chart"+(n?"-"+n:"")+"-"+a[e].chain);$("#"+q[0]+"-thumb").empty();for(e=0;e<q.length;e++)0==$("#"+q[e]).length?$("body").append('<div rel="'+n+'" id="'+q[e]+'" style="display:none"></div>'):$("#"+q[e]).empty(),0<e&&0==$('a[href="#'+q[e]+'"').length&&$("body").append('<a href="#'+q[e]+'" rel="lq-'+(n?n:"")+'" class="fancybox"/>'),$("#"+q[e]).empty();
n=!0;for(var k=0;k<q.length;k++){var c=0,h=0,g=0,u=!1;if(n){var d=$("#"+q[k]+"-thumb").closest(":visible").width();if(340<d){var l=12;c=45;h=30;g=40;d-=c;var m=400/620*d-g+h;u=!0}else m=.5*d,y&&(c=30,h=16),l=Math.max(15,m/10)}else l=20,c=45,h=30,g=40,d=620+c,m=400+g+h;for(var t=Raphael(q[k]+(n?"-thumb":""),d,m),v=99999,x=0,f=0;f<a.length;f++)if(!(0<k&&k-1!=f)){for(e=0;e<a[f].scores.length;e++)if(a[f].scores[e][1]){v=Math.min(a[f].scores[e][0],v);break}for(e=a[f].scores.length-1;-1<e;e--)if(a[f].scores[e][1]){x=
Math.max(a[f].scores[e][0],x);break}}var w=m-g-h,z=(d-c)/(x-v);t.rect(0,0,d,m).attr({fill:"#FFF",stroke:"#FFF"});if(n&&!u)t.rect(c,h,d-c,w).attr({stroke:"#DDD"}),y&&t.text(d/2,8,"Local Quality Estimate").attr({"text-anchor":"middle",fill:"#444","font-size":Math.max(8,d/24)}),t.text(d/2,m-8,"Residue Number").attr({"text-anchor":"middle",fill:"#444","font-size":Math.max(8,d/26)}),y&&(t.text(6,m/2+h/2,"Predicted Local").attr({"text-anchor":"middle",fill:"#666","font-size":Math.max(8,d/26)}).rotate(270,
6,m/2+h/2),t.text(18,m/2+h/2,"Similarity to Target").attr({"text-anchor":"middle",fill:"#666","font-size":Math.max(8,d/26)}).rotate(270,18,m/2+h/2));else{t.rect(c,h,d-c,w).attr({stroke:"#DDD"});u=14;t.text(d/2,10,"Local Quality Estimate"+(0<k?" - Chain "+a[k-1].chain:"")).attr({"text-anchor":"middle",fill:"#444","font-size":Math.max(8,d/26)});n?(t.text(6,m/2,"Predicted Local").attr({"text-anchor":"middle",fill:"#666","font-size":l}).rotate(270,6,m/2),t.text(18,m/2,"Similarity to Target").attr({"text-anchor":"middle",
fill:"#666","font-size":l}).rotate(270,18,m/2),u=l):t.text(10,m/2,"Predicted Local Similarity to Target").attr({dy:10,"text-anchor":"middle",fill:"#666","font-size":l}).rotate(270,10,m/2);t.text(c+(d-c)/2,m-8,"Residue Number").attr({"text-anchor":"middle",fill:"#666","font-size":l});for(f=0;1>=f;f+=.2)t.path("M"+c+" "+(w*f+h)+"L"+(c-5)+" "+(w*f+h)).attr({stroke:"#CCC","stroke-width":1}),t.text(c-12,w*f+h,(1-f).toFixed(1)).attr({fill:"#444","font-size":u});l=Math.floor((x-v)/8);l-=l%10;l=Math.max(10,
l);for(f=v;f<x;f++)0==f%l&&(e=c+(f-v)/(x-v)*(d-c),t.text(e,m-g+12,f).attr({fill:"#444","font-size":u}))}d="#e41a1c #377eb8 #4daf4a #984ea3 #ff7f00 #ffff33 #a65628 #f781bf".split(" ");for(f=m=0;f<a.length;f++){n&&p&&$(".alignTbl").each(function(){if(null!=$(this).data("templateData")){var e="chain";"target-template"!=$(this).data().templateData.type&&(e="keyseqchain");var c=$.cookie("colourScheme")&&"qmean_local"==$.cookie("colourScheme");$(this).find('tr[struc_id="'+p+'"]['+e+'="'+a[f].chain+'"] span').each(function(e,
w){for(var d=parseInt(w.getAttribute("s")),h=0;h<a[f].scores.length;h++)if(d==a[f].scores[h][0]){var m=a[f].scores[h][1];if(null!=m){w.setAttribute("q",a[f].scores[h][1]);c&&(.5>m?w.style.backgroundColor="rgba(255,80,0,.6)":(m=(m-.5)/.4,r=Math.round(255*(1-m)),b=Math.round(255*m),w.style.backgroundColor="rgba("+r+",90,"+b+",.6)"));break}}})}});g="";x=!1;if(0==k||k-1==f){g="";for(e=0;e<a[f].scores.length-1;e++)if(l=a[f].scores[e][0],(u=a[f].scores[e][1])&&a[f].scores[e+1][1]){if(""==g||x)g+="M"+(c+
z*(l-v))+" "+(w*(1-u)+h),x=!1;g+="L"+(c+(z*(l-v)+z))+" "+(w*(1-a[f].scores[e+1][1])+h)}else x=!0;g=t.path(g);g.attr({stroke:d[m],"stroke-width":n?1.5:2.5})}m=++m%8}n&&(n=!1,k--)}}}
function drawQMEANGlobal(a,n,p,y,e){var q=$("#qn-chart"+(p?"-"+p:"")+"-thumb,#qn-chart"+(p?"-"+p:""));if(a&&(p="qmeanGlobalTbl"+(p?p:""),e||!(0<$("#"+p+" tr").length))){q.empty();$("#"+p+" tr").remove();a.QMEAN4&&(a.qmean4_norm_score=a.qmean4_norm,delete a.qmean4_norm,a.qmean4_z_score=a.QMEAN4,delete a.QMEAN4,a.cbeta_z_score=a.cbeta,delete a.cbeta,a.interaction_z_score=a.all_atom,delete a.all_atom,a.packing_z_score=a.solvation,delete a.solvation,a.torsion_z_score=a.torsion,delete a.torsion);a.qmean4&&
(a.qmean4_norm_score=parseFloat(a.qmean4.norm),a.qmean4_z_score=parseFloat(a.qmean4.zscore),delete a.qmean4,a.cbeta_z_score=parseFloat(a.cbeta.zscore),delete a.cbeta,a.interaction_z_score=parseFloat(a.all_atom.zscore),delete a.all_atom,a.packing_z_score=parseFloat(a.solvation.zscore),delete a.solvation,a.torsion_z_score=parseFloat(a.torsion.zscore),delete a.torsion,delete a.acc_agreement,delete a.ss_agreement,delete a.qmean6);e=[["qmean4_z_score","QMEAN"],["cbeta_z_score","C\u03b2"],["interaction_z_score",
"All Atom"],["packing_z_score","solvation"],["torsion_z_score","torsion"]];for(var k="",c=0;c<e.length;c++)k+='<tr><td width="1">'+e[c][1]+'</td><td width="100%" style="padding:0px 2px 0px 2px;"><div id="'+p+"_"+e[c][0]+'">&nbsp;</div></td><td width="1" nowrap="nowrap" style="text-align:right">'+a[e[c][0]].toFixed(2)+"</td></tr>";$("#"+p).append(k);k=$("#"+p+"_"+e[0][0]).innerWidth();var h=$("#"+p+"_"+e[0][0]).parent().innerHeight();if(1>k||1>h)k=290,h=20;for(c=0;c<e.length;c++)$("#"+p+"_"+e[c][0]).html("");
for(var g=k/8,u=0;u<e.length;u++){var d=Raphael(p+"_"+e[u][0],k,h);d.rect(0,0,k,h).attr({fill:"0-rgb(245,61,61)-#fff:75-rgb(77,77,255)"});var l=h/4;for(c=1;8>c;c++)d.path("M"+g*c+" 0L"+g*c+" "+l).attr({stroke:"#555"}),d.path("M"+g*c+" "+(h-l)+"L"+g*c+" "+h).attr({stroke:"#555"});a&&(c=a[e[u][0]],c=Math.min(c,1.95),c=Math.max(c,-5.95),d.path("M"+(g*c+6*g)+" 0L"+(g*c+6*g)+" "+h).attr({stroke:"#222","stroke-width":3}))}var m=a.qmean4_norm_score,t=Math.min(600,n),v=!0;q.each(function(a,e){var c=0,f=0,
h=0;if(v){var d=$(this).closest("div:visible").width();if(340<d){var g=12;c=45;f=30;h=40;d-=c;var k=400/620*d-h+f}else k=.5*d,y&&(c=15,f=30),g=Math.max(15,k/10)}else g=20,c=45,f=30,h=40,d=617+c,k=398+h+f;var l=Raphael($(this).attr("id"),d,k),n=k-h-f,p=t/600*(d-c)+c,q=n-m/1.5*n+f;l.rect(0,0,d,k).attr({fill:"#FFF",stroke:"#FFF"});"undefined"===typeof localQMEANNormImage?l.image("/static/images/qmean_norm.png",c,f,d-c,n):l.image(localQMEANNormImage,c,f,d-c,n);l.rect(c,f,d-c,n).attr({stroke:"#DDD"});
l.text(p,q,String.fromCharCode(9733)).attr({"text-anchor":"middle",fill:"#F44","font-size":g});if(v)y&&(l.text((d+c)/2,8,"Comparison with Non-redundant").attr({"text-anchor":"middle",fill:"#444","font-size":Math.max(8,d/32)}),l.text((d+c)/2,22,"Set of PDB Structures").attr({"text-anchor":"middle",fill:"#444","font-size":Math.max(8,d/32)}),l.text(6,k/2+f/2,"Normalized QMEAN4").attr({"text-anchor":"middle",fill:"#666","font-size":Math.max(8,d/32)}).rotate(270,6,k/2+f/2)),l.rect(c+1,k-Math.max(16,d/
16),d-c-2,Math.max(16,d/16)).attr({fill:"#FFF","stroke-width":0}),l.text(d/2,k-8,"Protein Size (Residues)").attr({"text-anchor":"middle",fill:"#444","font-size":Math.max(8,d/32)});else{l.text((d+c)/2,10,"Comparison with Non-redundant Set of PDB Structures").attr({"text-anchor":"middle",fill:"#444","font-size":g});l.text(10,k/2,"Normalized QMEAN4 Score").attr({"text-anchor":"middle",fill:"#666","font-size":g}).rotate(270,10,k/2);l.text(c+(d-c)/2,k-12,"Protein Size (Residues)").attr({"text-anchor":"middle",
fill:"#666","font-size":g});for(g=100;600>g;g+=100)l.text(c+g*(d-c)/600,k-h+8,g).attr({fill:"#444","font-size":14});for(g=1.5;0<=g;g-=.5)l.text(c-12,g/1.5*n+f,(1.5-g).toFixed(1)).attr({fill:"#444","font-size":14})}v=!1})}};